package com.patui.Ui;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.patui.Logic.FrameSevice;
import com.patui.PatuiMe.R;
import com.patui.Utils.PhoneUtils;
import com.patui.widget.ImageAndText;
import com.patui.widget.ImageButton;
public class LoginLayout extends RelativeLayout{
   public  final static String 	    TAG="@___Patui.LoginLayout";
   private ImageView 				mImgTitleBarBg=null;
   private ImageButton 			    mImgBtnBack=null;
   private ImageAndText 			mImgTxtLogin=null;
   private ImageAndText 			mImgTxtOauthLogin=null;
   private TextView                 mTxtWeibo=null;
   private EditText  				mEtxtUser=null;
   private EditText  				mEtxtPsw=null;
   private final static int 		ID_LAYOUT_TITLE=1;
   private final static int 		ID_TXT_ACCOUT=2;
   private final static int 		ID_ETXT_ACCOUT=3;
   private final static int 		ID_TXT_PSW=4;
   private final static int 		ID_ETXT_PSW=5;
   private static final int         ID_IMGTXT_LOGIN = 6;
   private static final int         ID_IMGTXT_OAUTHLOGIN = 7;
   private static final int         ID_LAYOUT_LOGINGROUP = 8;
   public LoginLayout(Context context) {
		super(context);
		initLayout(context);
		// TODO Auto-generated constructor stub
	}

	private void initLayout(Context context) {
		// TODO Auto-generated method stub
		int[] colors = new int[2];
		colors[0] = 0xFFF4F4F4;
		colors[1] = 0xffDED9D8;
		GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
		this.setBackgroundDrawable(drawable);
		LayoutParams relativeParams=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
		relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		relativeParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		FrameLayout topTileFlayout=new FrameLayout(context);
		this.addView(topTileFlayout, relativeParams);
		topTileFlayout.setId(ID_LAYOUT_TITLE);
		
		FrameLayout.LayoutParams frameParams=new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
		frameParams.gravity=Gravity.LEFT;
		mImgTitleBarBg=new ImageView(context);
		mImgTitleBarBg.setImageResource(R.drawable.loginactivity_titlebar_bg_nor);
		mImgTitleBarBg.setScaleType(ScaleType.FIT_XY);
		topTileFlayout.addView(mImgTitleBarBg,frameParams);
		
		frameParams=new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		frameParams.gravity=Gravity.LEFT|Gravity.CENTER_VERTICAL;
		mImgBtnBack=new ImageButton(context,R.drawable.loginactivity_title_back,R.drawable.loginactivity_title_back_ed);
		topTileFlayout.addView(mImgBtnBack,frameParams);
		
		frameParams=new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		frameParams.gravity=Gravity.CENTER|Gravity.CENTER_VERTICAL;
		mTxtWeibo=new TextView(context);
		mTxtWeibo.setText("Weibo");
		
	    relativeParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	    relativeParams.addRule(RelativeLayout.BELOW,ID_LAYOUT_TITLE);
	    relativeParams.setMargins(PhoneUtils.getRealPixelW(20), PhoneUtils.getRealPixelW(20), 0, 0);
	    TextView mTxtAccount=new TextView(context);
	    mTxtAccount.setTextColor(0xff000000);
	    mTxtAccount.setTextSize(18.0f);
		Paint mPaint=mTxtAccount.getPaint();
		mPaint.setFakeBoldText(true);
		mTxtAccount.setText("Account");
		this.addView(mTxtAccount, relativeParams);
		mTxtAccount.setId(ID_TXT_ACCOUT);
		
	    relativeParams=new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
	    relativeParams.addRule(RelativeLayout.BELOW,ID_TXT_ACCOUT);
	    relativeParams.setMargins(PhoneUtils.getRealPixelW(20), PhoneUtils.getRealPixelW(2), PhoneUtils.getRealPixelW(20), 0);
	    mEtxtUser=new EditText(context);
		this.addView(mEtxtUser, relativeParams);
		mEtxtUser.setId(ID_ETXT_ACCOUT);
		
	    relativeParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	    relativeParams.addRule(RelativeLayout.BELOW,ID_ETXT_ACCOUT);
	    relativeParams.setMargins(PhoneUtils.getRealPixelW(20), PhoneUtils.getRealPixelW(8), 0, 0);
	    TextView mTxtPsw=new TextView(context);
	    mTxtPsw.setTextColor(0xff000000);
	    mTxtPsw.setTextSize(18.0f);
		mPaint=mTxtPsw.getPaint();
		mPaint.setFakeBoldText(true);
		mTxtPsw.setText("PassWord");
		this.addView(mTxtPsw, relativeParams);
		mTxtPsw.setId(ID_TXT_PSW);
		
		
	    relativeParams=new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
	    relativeParams.addRule(RelativeLayout.BELOW,ID_TXT_PSW);
	    relativeParams.setMargins(PhoneUtils.getRealPixelW(20), PhoneUtils.getRealPixelW(2), PhoneUtils.getRealPixelW(20), 0);
	    mEtxtPsw=new EditText(context);
		this.addView(mEtxtPsw, relativeParams);
		mEtxtPsw.setId(ID_ETXT_PSW);
		
	    relativeParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	    relativeParams.addRule(RelativeLayout.BELOW,ID_ETXT_PSW);
	    relativeParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
	    relativeParams.topMargin=PhoneUtils.getRealPixelW(25);
	    LinearLayout loginGroupLayout=new LinearLayout(context);
	    loginGroupLayout.setOrientation(LinearLayout.HORIZONTAL);
	    loginGroupLayout.setId(ID_LAYOUT_LOGINGROUP);
	    this.addView(loginGroupLayout, relativeParams);
	    
	    LinearLayout.LayoutParams linearParams=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	    linearParams.weight=1;
	    linearParams.rightMargin=PhoneUtils.getRealPixelW(10);
	    mImgTxtLogin=new ImageAndText(context,R.drawable.loginactivity_btn_login,R.drawable.loginactivity_btn_login_ed,"Login");
	    mImgTxtLogin.setId(ID_IMGTXT_LOGIN);
	    mImgTxtLogin.setOnClickListener(mOnClickListener);
	    loginGroupLayout.addView(mImgTxtLogin,linearParams);
	    
	    mImgTxtOauthLogin=new ImageAndText(context,R.drawable.loginactivity_btn_login,R.drawable.loginactivity_btn_login_ed,"OAuth Login");
	    mImgTxtOauthLogin.setId(ID_IMGTXT_OAUTHLOGIN);
	    mImgTxtOauthLogin.setOnClickListener(mOnClickListener);
	    loginGroupLayout.addView(mImgTxtOauthLogin,linearParams);
	    
	    relativeParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	    relativeParams.addRule(RelativeLayout.BELOW,ID_LAYOUT_LOGINGROUP);
	    relativeParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
	    relativeParams.topMargin=PhoneUtils.getRealPixelW(21);
	    ImageView mImgSplitLine=new ImageView(context);
	    mImgSplitLine.setImageResource(R.drawable.loginactivity_group_divider);
		this.addView(mImgSplitLine, relativeParams);
		
		}
	  private OnClickListener mOnClickListener=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case ID_IMGTXT_LOGIN:
			case ID_IMGTXT_OAUTHLOGIN:
			//FrameSevice.addStartActivityTask(AlllActivityName.EditWeiboActivity);	
	        //FrameSevice.addStartActivityTask(AlllActivityName.MainTabActivity);
			FrameSevice.addLoginTask(1);
			//uploadImage();
				
				break;

			default:
				break;
			}
			// TODO Auto-generated method stub
			
		}
	};


}
